This solution literally came to me in a dream. Three days spent on the previous one, WASTED.